//
//  ListenBookViewController.m
//  彩虹儿歌
//
//  Created by SXS on 15/7/3.
//  Copyright (c) 2015年 HelloBaby. All rights reserved.
//

#import "ListenBookViewController.h"
#import "ListenBookViewCell.h"
#import "HeaderViewCell.h"
#import "ListenBookModels.h"
#import "RequestManager.h"
#import "MacroHeader.h"

@interface ListenBookViewController ()<RequestDelegate,UICollectionViewDelegateFlowLayout>

@property (nonatomic ,retain) NSMutableArray *dataSuurceArr;
//@property (nonatomic ,retain)

@end

@implementation ListenBookViewController

- (void)dealloc
{
    self.dataSuurceArr = nil;
    [super dealloc];
}

//注册Nib文件

static NSString * const reuseIdentifier = @"Cell";
static NSString * const reuseIdentifierHeader = @"headerCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView *backgroundImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"xiaohua01"]];
    [self.view addSubview:backgroundImgV];

     self.automaticallyAdjustsScrollViewInsets = NO;
    

    self.dataSuurceArr = [NSMutableArray array];
    
    UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *) self.collectionViewLayout;
    flowLayout.minimumInteritemSpacing = 15;
    flowLayout.minimumLineSpacing = 15;
    flowLayout.sectionInset = UIEdgeInsetsMake(15, 15, 15, 15);


    self.collectionView.backgroundColor = [UIColor clearColor];

    [self.collectionView registerClass:[ListenBookViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
    [self.collectionView registerClass:[HeaderViewCell class] forCellWithReuseIdentifier:reuseIdentifierHeader];
    
    [self.view addSubview:self.collectionView];
    
    [self startRequest];
    
}

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 2;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    } else {
        return 12;
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        HeaderViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifierHeader forIndexPath:indexPath];
        return cell;
    } else {
        ListenBookViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
        cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
        return cell;
    }
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return CGSizeMake((SCREEN_WIDTH - 30), (SCREEN_WIDTH - 30) / 2);
    } else {
        return CGSizeMake((SCREEN_WIDTH - 60)/3, (SCREEN_WIDTH - 60)/3);
    }
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
    if (section == 1) {
        CGSize size = CGSizeMake(0, 50);
        return size;
    } else {
        return CGSizeZero;
    }
}

#pragma mark - 数据请求

- (void)startRequest
{
    
}

- (void)requestDidFinishWithData:(NSData *)data
{
    
}

- (void)requestError:(NSError *)error
{
    NSLog(@"%@",error);
}


#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
